package com.leyou.common.advice;

import com.leyou.common.exception.LyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * <h3>leyou-project</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-05-20 21:36
 **/
//拦截controller层下的运行时异常
@ControllerAdvice
@Slf4j
public class ControllerExceptionAdvice {

    //拦截所有LyException
    @ExceptionHandler(LyException.class)
    public ResponseEntity<String> handleLyException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }

}
